<?php

class Application_Form_User extends Application_Form_Basic
{

    public function init()
    {
        $this ->setMethod ( 'post' );
        
        $this->addElement(
            'hidden', 
            'id', 
            array(
                'value' => ''
            )
        );
        
        $roles = Application_Model_RolesService::getInstance()->getRoles();
        
        $this->addElement( 
            'select', 
            'role',
    		array(
                'label'			=> 'Роль :',
                'value'			=> 'client',
                'multiOptions'	=> $roles,
                'required' => true
            )
		);
        
        $this->addDisplayGroup(
			array( 'role' ),
			'role_group'
		);
        
        $group = $this->getDisplayGroup ('role_group');
        $group->removeDecorator ('DtDdWrapper');
        
        $this->addElement (
            'text', 
            'surname', 
            array ( 
                'label' => 'Прізвище:',
                'required' => true,
                'validators' => array(
                    array ('NotEmpty', true, 
                        array (
                            'messages' => array (
                                'isEmpty' => 'Поле не може бути пустим!' 
                            )
                        ) 
                    ),
                    array('stringLength', false, array(3, 20))
                )
            ) 
        );
        
        $this->addDisplayGroup(
			array( 'surname' ),
			'surname_group'
		);
        
        $group = $this->getDisplayGroup ('surname_group');
        $group->removeDecorator ('DtDdWrapper');
        
        $this->addElement ( 
            'text', 
            'name',
            array ( 
                'label' => 'Ім\'я:',
                'required' => true,
                'validators' => array(
                    array ('NotEmpty', true, 
                        array (
                            'messages' => array (
                                'isEmpty' => 'Поле не може бути пустим!' 
                            )
                        ) 
                    ),
                    array('stringLength', false, array(3, 20))
                )
            )
        );
        
        $this->addDisplayGroup(
			array( 'name' ),
			'name_group'
		);
        
        $group = $this->getDisplayGroup ('name_group');
        $group->removeDecorator ('DtDdWrapper');
		
        $this->addElement ( 
            'text', 
            'patronymic',
            array ( 
                'label' => 'По-батькові:',
                'required' => true,
                'validators' => array(
                    array ('NotEmpty', true, 
                        array (
                            'messages' => array (
                                'isEmpty' => 'Поле не може бути пустим!' 
                            )
                        ) 
                    ),
                    array('stringLength', false, array(2, 20))
                )
            )
        );
        
         $this->addDisplayGroup(
			array( 'patronymic' ),
			'patronymic_group'
		);
        
        $group = $this->getDisplayGroup ('patronymic_group');
        $group->removeDecorator ('DtDdWrapper');
        
        $this->addElement ( 
            'text', 
            'login', 
            array (
                'label' => 'Логін:', 
                'required' => true,
                'validators' => array(
                    array ('NotEmpty', true, 
                        array (
                            'messages' => array (
                                'isEmpty' => 'Поле не може бути пустим!' 
                            )
                        )
                    ),
                    array('alnum'),
                    array('stringLength', true, array(5, 20)),
                    array('Db_NoRecordExists', false, array(
                        'table' => 'users', 
                        'field' => 'login'
                    )),
                )
            ) 
        );
        
        $this->addDisplayGroup(
			array( 'login' ),
			'login_group'
		);
        
        $group = $this->getDisplayGroup ('login_group');
        $group->removeDecorator ('DtDdWrapper');
        
		$this->addElement ( 
            'password', 
            'password', 
            array (
                'label' => 'Пароль:', 
                'required' => true,
                'validators' => array(
                    array ('NotEmpty', true, 
                        array (
                            'messages' => array (
                                'isEmpty' => 'Поле не може бути пустим!' 
                            )
                        ) 
                    ),
                    array('stringLength', false, array(6, 20))
                )
            ) 
        );
        
        $this->addDisplayGroup(
			array( 'password' ),
			'password_group'
		);
        
        $group = $this->getDisplayGroup ('password_group');
        $group->removeDecorator ('DtDdWrapper');
        
		$this->addElement (
            'submit', 
            'submit', 
            array (
                'ignore' => true, 
                'label' => 'Add User' 
            ) 
        );
        
        $this->addDisplayGroup(
			array( 'submit' ),
			'buttos_group',
            array(
                'class' => 'group_buttons'
            )
		);
        
        $group = $this->getDisplayGroup ('buttos_group');
        $group->removeDecorator ('DtDdWrapper');
    }


}

